home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_weap_saber_m.cog < prev    next >
Text File  |  1998-02-25  |  19KB  |  643 lines

  1. # Jedi Knight Missions Cog Script
  2. #
  3. # WEAP_SABER_M.COG
  4. #
  5. # WEAPON Script - Lightsaber
  6. #
  7. # [CYW] + [RF] + [YB]
  8. #
  9. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  10. # ========================================================================================
  11.  
  12.  
  13. symbols
  14.  
  15. message  startup
  16. message  activated
  17. message  deactivated
  18. message  selected
  19. message  deselected
  20. message  user0
  21. message  newplayer
  22. message  autoselect
  23. message  timer
  24. message  fire
  25. message  killed
  26. message    joined
  27.  
  28. # ........................................................................................
  29.  
  30. model    povModel=sabv.3do             local
  31. model    povModel_m=sabv_m.3do         local
  32. model    saberMesh=sabg.3do            local
  33.  
  34. # ........................................................................................
  35. # POV animations
  36.  
  37. keyframe mountAnim=SabVmnt.key         local
  38. keyframe dismountAnim=SabVdis.key      local
  39. keyframe holdAnim=SabVhold.key         local
  40.  
  41. keyframe povSnapAnim1=SabVf1.key       local
  42. keyframe povSnapAnim2=SabVf2.key       local
  43. keyframe povSnapAnim3=SabVf1.key       local
  44.  
  45. keyframe povPreFireAnim=SabVrdy.key    local
  46. keyframe povFireAnimF1=SabVsnp1.key    local
  47. keyframe povFireAnimF2=SabVsnp2.key    local
  48. keyframe povFireAnimB1=SabVb1.key      local
  49. keyframe povFireAnimB2=SabVb2.key      local
  50. keyframe povFireAnimL1=SabVl1.key      local
  51. keyframe povFireAnimR1=SabVr1.key      local
  52. keyframe povChargeAnim=SabVch.key      local
  53.  
  54. keyframe povPreBlockAnim=SabVblk.key   local
  55.  
  56. # ........................................................................................
  57. # External animations
  58.  
  59. keyframe preFireAnimL=KYreadyl.key     local
  60. keyframe preFireAnimR=KYreadyr.key     local
  61. keyframe fireAnimF1=KYsnap1.key        local
  62. keyframe fireAnimF2=KYsnap2.key        local
  63. keyframe fireAnimB1=KYsabrb1.key       local
  64. keyframe fireAnimB2=KYsabrb2.key       local
  65. keyframe fireAnimL1=KYsabrl1.key       local
  66. keyframe fireAnimR1=KYsabrr1.key       local
  67.  
  68. keyframe snapAnim1=KYsabrf1.key        local
  69. keyframe snapAnim2=KYsabrf2.key        local
  70. keyframe snapAnim3=KYsabrf1.key        local
  71. keyframe chargeAnim=KYcharge.key       local
  72.  
  73. keyframe preBlockAnim=KYblock.key      local
  74. keyframe holsterAnim=kyhlstr.key       local
  75.  
  76. # ........................................................................................
  77.  
  78. sound    dismountSound=LtSaberOff01.WAV         local
  79. sound    mountSound=LtSaberOn01.WAV             local
  80. sound    hitSound01=LtSaberHit01.WAV            local
  81. sound    hitSound02=LtSaberHit02.WAV            local
  82. sound    hitSound03=LtSaberHit03.WAV            local
  83. sound    hitSound12=LtSaberHit12.WAV            local
  84. sound    hitSound14=LtSaberHit14.WAV            local
  85. sound    swingSound01=LtSaberSwing01.WAV        local
  86. sound    swingSound02=LtSaberSwing02.WAV        local
  87. sound    swingSound03=LtSaberSwing03.WAV        local
  88. sound    swingSound04=LtSaberSwing04.WAV        local
  89. sound    swingSound05=LtSaberSwing05.WAV        local
  90. sound    swingSound06=LtSaberSwing06.WAV        local
  91. sound    swingSound07=LtSaberSwing07.WAV        local
  92. sound    swingSound08=LtSaberSwing08.WAV        local
  93. sound    swingSoundDbl01=LtSaberSwingDbl01.WAV  local
  94. sound    humSound01=LtSaberLp01.WAV             local
  95.  
  96. flex     damage                                 local
  97. flex     bladeLen                               local
  98. flex     holsterWait                            local
  99.  
  100. thing    player                                 local
  101. thing    antagonist                             local
  102.  
  103. vector   ppos                                   local
  104. vector   apos                                   local
  105. vector   diff                                   local
  106. vector   thrust                                 local
  107.  
  108. flex     damage                                 local
  109. flex     type                                   local
  110. flex     dot                                    local
  111.  
  112. int        iAlignmentPriority=-1    local
  113.  
  114. # ........................................................................................
  115. # Animation tracks
  116.  
  117. int      mountAnimID=-1                         local
  118. int      preAnimID=-1                           local
  119. int      povPreAnimID=-1                        local
  120. int      slashAnimID=-1                         local
  121. int      povSlashAnimID=-1                      local
  122.  
  123. # ........................................................................................
  124.  
  125. int      mode                                   local
  126. int      slash                                  local
  127. int      nextAttack                             local    # 0=right 1=left
  128. int      humChannel=-1                          local
  129. int      holsterTrack=-1                        local
  130. int      slashSound=-1                          local
  131.  
  132. int      assign                                 local
  133. int      nosaber=1                              local
  134.  
  135. vector   shakePos                               local
  136. vector   shakeAngle                             local
  137.  
  138. cog      kyleCog                                local
  139.  
  140. end
  141.  
  142. # ========================================================================================
  143.  
  144. code
  145.  
  146. startup:
  147.    // Set up player with saber.
  148.    player = GetLocalPlayerThing();
  149.  
  150.    kyleCog = GetThingClassCog(player);
  151.  
  152.    ClearActorFlags(player, 0x2000);
  153.    jkDisableSaber(player);
  154.    slash = 0;
  155.    nextAttack = 0;
  156.    slashAnimID=-1;
  157.    povSlashAnimID=-1;
  158.    return;
  159.  
  160. # ........................................................................................
  161.  
  162. timer:
  163.    id = GetSenderId();
  164.  
  165.    if (id == 0)
  166.    {
  167.             // Only play the hum sound if we still have the saber up.
  168.         if ((GetCurWeapon( player ) == 11) && !nosaber)
  169.         {
  170.             // Play mounting sound.
  171.             PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
  172.     
  173.             // Stop humming sound
  174.             if(humChannel != -1)
  175.             {
  176.                 StopSound( humChannel, 0.5 );
  177.                 humChannel = -1;
  178.             }
  179.     
  180.             humChannel = PlaySoundThing(humSound01, player, 1.0, -1, -1, 0x81);
  181.             jkSetFlags(player, 0x5);
  182.         }
  183.    }
  184.    else
  185.    if (id == 1)
  186.    {
  187.       // Make sure a loose timer doesn't come in and reset the block after we deselect the saber.
  188.       if (nosaber == 0)
  189.          SetActorFlags(player, 0x2000);
  190.    }
  191.    else
  192.    if (id == 2)
  193.    {
  194.       StopKey(player, holsterTrack, 0.0);
  195.    }
  196.    if (id == 3)
  197.    {
  198.       SetInv(player, 89, 0);
  199.    }
  200.    if (id == 10)
  201.    {
  202.         if (GetCurWeapon( player ) == 11)
  203.             jkSetFlags(player, 0x81);
  204.     }
  205.  
  206.    return;
  207.  
  208. # ........................................................................................
  209.  
  210. selected:
  211.    // Cannot throw the saber in those 1.25 seconds
  212.    SetInv(player, 89, 1);
  213.    SetTimerEx(1.25, 3, 0, 0);
  214.  
  215.    assign = GetSenderRef();
  216.  
  217.    // Go to external
  218.    if ((jkGetSaberCam() == 1) && (GetCurrentCamera() == 0) && (GetPrimaryFocus(0) == player))
  219.       CycleCamera();
  220.  
  221.    // Setup the meshes and models.
  222.    if (GetInv(player, 67) == 0.0)
  223.       jkSetPOVModel(player, povModel);    // Kyle hand
  224.    else
  225.       jkSetPOVModel(player, povModel_m);  // Mara Hand
  226.    SetArmedMode( player, 2 );
  227.    jkSetWeaponMesh( player, saberMesh );
  228.    jkSetWaggle(player, '10.0 7.0 0.0', 350);
  229.  
  230.    if (assign == 0)
  231.    {
  232.       // Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
  233.       // The animation is held at the last frame after it is played.
  234.       PlayMode(player, 42);
  235.       mountAnimID = jkPlayPOVKey( player, mountAnim, 0, 0x14 );
  236.       SetTimerEx(0.7, 0, 0, 0);
  237.    }
  238.    else
  239.    {
  240.       mountAnimID = jkPlayPOVKey( player, holdAnim, 0, 0x14 );
  241.  
  242.         // Stop humming sound
  243.         if(humChannel != -1)
  244.         {
  245.             StopSound( humChannel, 0.5 );
  246.             humChannel = -1;
  247.         }
  248.  
  249.       humChannel = PlaySoundThing(humSound01, player, 1.0, -1, -1, 0x81);
  250.       jkSetFlags(player, 0x80);
  251.    }
  252.  
  253.    SetMountWait(player, GetKeyLen(mountAnim));
  254.  
  255.    // Set saber flags, and allow activation of the weapon
  256.    SetCurWeapon( player, GetWeaponBin(11) );
  257.  
  258.     if (iAlignmentPriority != -1)
  259.     {
  260.         aiRemoveAlignmentPriority(iAlignmentPriority);
  261.  
  262.         iAlignmentPriority = -1;
  263.     }
  264.  
  265.     iAlignmentPriority = aiAddAlignmentPriority(1.0, 2);
  266.  
  267.    // Set autoblock on.
  268.    SetActorFlags(player, 0x2000);
  269.    jkDisableSaber(player);
  270.    nosaber = 0;
  271.    return;
  272.  
  273. # ........................................................................................
  274.  
  275. deselected:
  276.    // Back to POV
  277.    if ((jkGetSaberCam() == 1) && (GetCurrentCamera() == 1) && (GetPrimaryFocus(1) == player))
  278.       CycleCamera();
  279.  
  280.    // Shrink saber.
  281.    jkSetFlags(player, 0x8);
  282.  
  283.    // Dismount the Lightsaber.
  284.    PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
  285.    jkPlayPOVKey( player, dismountAnim, 0, 18 );
  286.  
  287.    holsterWait = GetKeyLen(holsterAnim);
  288.    SetMountWait(player, holsterWait);
  289.    holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
  290.    SetTimerEx(holsterWait, 2, 0.0, 0.0);
  291.  
  292.    call user0;
  293.  
  294. //    DamageThing(player, 200.0, 16, player);
  295.  
  296.    return;
  297.  
  298. # ........................................................................................
  299.  
  300. // This part is called directly from Force Saber Throw to get
  301. // a fast dismount but clear all the saber stuff properly...
  302. user0:
  303.    // if the mount anim is still playing stop it
  304.    if (mountAnimID != -1)
  305.    {
  306.       jkStopPOVKey( player, mountAnimID, 0 );
  307.       mountAnimID = -1;
  308.    }
  309.  
  310.     KillTimerEx(0);
  311.  
  312.    jkSetWaggle(player, '0.0 0.0 0.0', 0);
  313.  
  314.    // Clear variables
  315.    slash = 0;
  316.    nextAttack = 0;
  317.    slashAnimID = -1;
  318.    povSlashAnimID = -1;
  319.  
  320.    // Stop humming sound
  321.    if(humChannel != -1)
  322.    {
  323.       StopSound( humChannel, 0.5 );
  324.       humChannel = -1;
  325.    }
  326.  
  327.     if (iAlignmentPriority != -1)
  328.     {
  329.         aiRemoveAlignmentPriority(iAlignmentPriority);
  330.  
  331.         iAlignmentPriority = -1;
  332.     }
  333.     
  334.     // Waylay any hum sound that hasn't started yet.
  335.    KillTimerEx(0);
  336.  
  337.    // Disable autoblock
  338.    KillTimerEx(1);
  339.    ClearActorFlags(player, 0x2000);
  340.    jkDisableSaber(player);
  341.    nosaber = 1;
  342.  
  343.    Return;
  344.  
  345. # ........................................................................................
  346.  
  347. activated:
  348.    mode = GetSenderRef();
  349.  
  350.    jkSetWaggle(player, '0.0 0.0 0.0', 0);
  351.  
  352.    if (mode > 1)
  353.       return;
  354.  
  355.    povPreAnimID = -1;
  356.    preAnimID = -1;
  357.  
  358.    ActivateWeapon( player, 0.5, mode );
  359.  
  360.    // Disable autoblock
  361.    ClearActorFlags(player, 0x2000);
  362.  
  363.    return;
  364.  
  365. # ........................................................................................
  366.  
  367. deactivated:
  368.    mode = GetSenderRef();
  369.  
  370.    jkSetWaggle(player, '10.0 7.0 0.0', 350);
  371.    DeactivateWeapon( player, mode );
  372.  
  373.    // Enable autoblock
  374.    SetTimerEx(0.5, 1, 0, 0);
  375.  
  376.    return;
  377.  
  378. # ........................................................................................
  379.  
  380. fire:
  381.    // Stop block animations, by sending a message to kyle.cog.
  382.    SendMessage( kyleCog, user0 );
  383.  
  384.     // Tell kyle.cog that the player has done something to attract attention.
  385.     SendMessageEx(kyleCog, user1, 3.0, 0, 0, 0);
  386.  
  387.    // Underwater saber attacks.
  388.    if (GetMajorMode(player) == 5)
  389.    {
  390.       jkEnableSaber( player, 50, 0.15, 0.25 );
  391.  
  392.       if (nextAttack == 0)
  393.       {
  394.          PlayMode( player, 8);
  395.          jkPlayPOVKey( player, povFireAnimR1, 2, 0x38 );
  396.          nextAttack = 1;
  397.       }
  398.       else
  399.       {
  400.          PlayMode( player, 18);
  401.          jkPlayPOVKey( player, povFireAnimL1, 2, 0x38 );
  402.          nextAttack = 0;
  403.       }
  404.  
  405.       shakePos = VectorScale(RandVec(),.001);
  406.       shakeAngle = VectorScale(RandVec(),.5);
  407.       SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  408.  
  409.       SetFireWait(player, 1.0);
  410.  
  411.       slashSound = Rand()*7;
  412.       PlaySoundThing(swingSound01[slashSound], player, 1.0, -1, -1, 0x80);
  413.    }
  414.    else
  415.    {
  416.       mode = GetSenderRef();
  417.       if (mode == 0)
  418.       {
  419.          // If we do another attack, reset the quick slash counter.
  420.          thrust = GetThingThrust( player );
  421.  
  422.          // RIGHT Regular Strike
  423.          if (VectorX(thrust) > 0)
  424.          {
  425.             jkEnableSaber( player, 50, 0.15, 0.25 );
  426.  
  427.             jkPlayPOVKey( player, povFireAnimR1, 2, 0x38 );
  428.             PlayKey(player, fireAnimR1, 1, 0x38);
  429.  
  430.             shakePos = VectorScale(RandVec(),.001);
  431.             shakeAngle = VectorScale(RandVec(),.5);
  432.             SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  433.  
  434. //          PlaySoundThing(swingSound02, player, 1.0, -1, -1, 0x80);
  435.             slashSound = Rand()*7;
  436.             PlaySoundThing(swingSound01[slashSound], player, 1.0, -1, -1, 0x80);
  437.             SetFireWait(player, 0.8);
  438.          }
  439.          else
  440.          // LEFT Regular Strike
  441.          if (VectorX(thrust) < 0)
  442.          {
  443.             jkEnableSaber( player, 50, 0.15, 0.25 );
  444.  
  445.             jkPlayPOVKey( player, povFireAnimL1, 2, 0x38 );
  446.             PlayKey(player, fireAnimL1, 1, 0x38);
  447.  
  448.             shakePos = VectorScale(RandVec(),.001);
  449.             shakeAngle = VectorScale(RandVec(),.5);
  450.             SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  451.  
  452. //          PlaySoundThing(swingSound02, player, 1.0, -1, -1, 0x80);
  453.             slashSound = Rand()*7;
  454.             PlaySoundThing(swingSound01[slashSound], player, 1.0, -1, -1, 0x80);
  455.             SetFireWait(player, 0.8);
  456.          }
  457.          else
  458.          // BACKWARDS Strike
  459.          if (VectorY(thrust) < -0.1)
  460.          {
  461.             jkEnableSaber( player, 50, 0.15, 0.25 );
  462.  
  463.             if (nextAttack == 0)
  464.             {
  465.                jkPlayPOVKey( player, povFireAnimB1, 2, 0x38 );
  466.                PlayKey(player, fireAnimB1, 2, 0x38);
  467.                nextAttack = 1;
  468.             }
  469.             else
  470.             {
  471.                jkPlayPOVKey( player, povFireAnimB2, 2, 0x38 );
  472.                PlayKey(player, fireAnimB2, 2, 0x38);
  473.                nextAttack = 0;
  474.             }
  475.             shakePos = VectorScale(RandVec(),.001);
  476.             shakeAngle = VectorScale(RandVec(),.5);
  477.             SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  478.  
  479.             slashSound = Rand()*7;
  480.             PlaySoundThing(swingSound01[slashSound], player, 1.0, -1, -1, 0x80);
  481.             SetFireWait(player, 0.8);
  482.          }
  483.          else
  484.          // STANDING Strike
  485.          if (VectorY(thrust) < 0.1)
  486.          {
  487.             jkEnableSaber( player, 50, 0.25, 0.7 );
  488.  
  489.             if (nextAttack == 0)
  490.             {
  491.                jkPlayPOVKey( player, povFireAnimF1, 2, 0x38 );
  492.                PlayKey(player, fireAnimF1, 2, 0x38);
  493.                nextAttack = 1;
  494.             }
  495.             else
  496.             {
  497.                jkPlayPOVKey( player, povFireAnimF2, 2, 0x38 );
  498.                PlayKey(player, fireAnimF2, 2, 0x38);
  499.                nextAttack = 0;
  500.             }
  501.  
  502.             shakePos = VectorScale(RandVec(),.001);
  503.             shakeAngle = VectorScale(RandVec(),.5);
  504.             SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  505.  
  506. //          PlaySoundThing(swingSound02, player, 1.0, -1, -1, 0x80);
  507.             slashSound = Rand()*7;
  508.             PlaySoundThing(swingSound01[slashSound], player, 1.0, -1, -1, 0x80);
  509.             SetFireWait(player, 0.8);
  510.          }
  511.          else
  512.          {
  513.             // QUICK slash.
  514.             if (slash == 0)
  515.             {
  516.                // If after a second, we haven't attacked again, reset slash to 0.
  517.                jkEnableSaber( player, 40, 0.15, 0.25 );
  518.  
  519.                povSlashAnimID = jkPlayPOVKey( player, povSnapAnim1, 2, 0x38);
  520.                slashAnimID = PlayKey(player, snapAnim1, 1, 0x38);
  521.                PlaySoundThing(swingSound01, player, 1.0, -1, -1, 0x80);
  522.  
  523.                shakePos = VectorScale(RandVec(),.001);
  524.                shakeAngle = VectorScale(RandVec(),.5);
  525.                SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  526.  
  527.                SetFireWait(player, 0.25);
  528.                slash = 1;
  529.             }
  530.             else
  531.             if (slash == 1)
  532.             {
  533.                // Allow another second for the 3rd attack.
  534.                jkEnableSaber( player, 40, 0.15, 0.25 );
  535.  
  536.                povSlashAnimID = jkPlayPOVKey( player, povSnapAnim2, 2, 0x38 );
  537.                slashAnimID = PlayKey(player, snapAnim2, 1, 0x38);
  538.                PlaySoundThing(swingSound03, player, 1.0, -1, -1, 0x80);
  539.  
  540.                shakePos = VectorScale(RandVec(),.001);
  541.                shakeAngle = VectorScale(RandVec(),.5);
  542.                SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  543.  
  544.                SetFireWait(player, 0.25);
  545.                slash = 2;
  546.             }
  547.             else
  548.             if (slash == 2)
  549.             {
  550.                jkEnableSaber( player, 60, 0.2, 0.25 );
  551.  
  552.                povSlashAnimID = jkPlayPOVKey( player, povSnapAnim3, 2, 0x38 );
  553.                slashAnimID = PlayKey(player, snapAnim3, 1, 0x38);
  554.                PlaySoundThing(swingSound02, player, 1.0, -1, -1, 0x80);
  555.  
  556.                shakePos = VectorScale(RandVec(),.001);
  557.                shakeAngle = VectorScale(RandVec(),.5);
  558.                SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  559.  
  560.                SetFireWait(player, 1.0);
  561.                slash = 0;
  562.             }
  563.          }
  564.       }
  565.       // mode == 1
  566.       else
  567.       {
  568.          // HEAVY slash.
  569.          {
  570.             jkEnableSaber( player, 160, 0.3, 1.2 );
  571.             jkPlayPOVKey( player, povChargeAnim, 2, 0x38 );
  572.             PlayKey(player, chargeAnim, 2, 0x38);
  573.  
  574.             shakePos = VectorScale(RandVec(),.001);
  575.             shakeAngle = VectorScale(RandVec(),.5);
  576.             SetPOVShake(shakePos, shakeAngle, .05, 80.0);
  577.  
  578.             PlaySoundThing(swingSoundDbl01, player, 1.0, -1, -1, 0x80);
  579.             SetFireWait(player, 2.0);
  580.          }
  581.       }
  582.    }
  583.    return;
  584.  
  585. # ........................................................................................
  586.  
  587. newplayer:
  588.    slash = 0;
  589.    nextAttack = 0;
  590.    slashAnimID=-1;
  591.    povSlashAnimID=-1;
  592.    // Disable autoblock
  593.    ClearActorFlags(player, 0x2000);
  594.    jkDisableSaber(player);
  595.  
  596.    // Back to POV, since the saber should never get autoselected at start for a multiplayer game.
  597.    if ((jkGetSaberCam() == 1) && (GetCurrentCamera() == 1) && (GetPrimaryFocus(1) == player))
  598.       CycleCamera();
  599.  
  600.    return;
  601.  
  602. # ........................................................................................
  603.  
  604. joined:
  605.     SetTimerEx(1.0, 10, 0, 0);
  606.     return;
  607.  
  608. # ........................................................................................
  609.  
  610. autoselect:
  611.    // Return the saber when out of everthing except the fists
  612.  
  613.    // If the player has the weapon
  614.    if(GetInv(player, GetWeaponBin(11)) != 0.0)
  615.    {
  616.       ReturnEx(200.0);
  617.    }
  618.    else
  619.    {
  620.       ReturnEx(-1.0);
  621.    }
  622.  
  623.    Return;
  624.  
  625. # ........................................................................................
  626.  
  627. killed:
  628.    if (GetLocalPlayerThing() == GetSenderRef())
  629.    {
  630.       if (GetCurWeapon(player) == 11)
  631.       {
  632.          PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
  633.  
  634.          SetCurWeapon( player, GetWeaponBin(1) );
  635.       }
  636.       nosaber = 1;
  637.    }
  638.    Return;
  639.  
  640.  
  641. end
  642.  
  643.